/*
 * @Author: Aiden.chen
 * @Date: 2023-03-09 17:25:54
 * @LastEditors: Aiden.chen
 * @LastEditTime: 2023-03-10 09:37:16
 * @Description: 
 */
export default {
    data() {
        return {
            windowSize: {
                width: 0,
                height: 0
            }
        };
    },
    created() {
        this.resizeHandler = this.debounce(this.resizeHandler, 200);
        window.addEventListener('resize', this.resizeHandler);
    },
    mounted() {
        this.resizeHandler();
    },
    beforeDestroy() {
        window.removeEventListener('resize', this.resizeHandler);
    },
    methods: {
        resizeHandler() {
            this.windowSize.width = window.innerWidth;
            this.windowSize.height = window.innerHeight;
        },
        debounce(fn, delay) {
            let timerId;
            return function () {
                const context = this;
                const args = arguments;
                clearTimeout(timerId);
                timerId = setTimeout(function () {
                    fn.apply(context, args);
                }, delay);
            };
        }
    }
};
